<?php

namespace App\Models;

use DB;
use Illuminate\Database\Eloquent\Model;

class TeamPerson extends Model
{
    protected $table = 'team_person';
    public $timestamps = false;
    protected $guarded = [];
    public static function getTeamPerson($scene_id=null){
        if($scene_id!=null){
            $team_person = self::where('scene_id',$scene_id)->get(['type','percent as total']);
        }else{
            $team_person = self::select('type', DB::raw('sum(percent) as total'))
                ->groupBy('type')
                ->get();
        }
        foreach ($team_person as $val){
            $val->type=config('options.flow_source')[$val->type];
        }
        return $team_person;
    }
}